# !/usr/bin/python3
# -*- coding: UTF-8 -*-

import os
import sys
import mysql.connector
from mysql.connector import Error
import pytest
# 添加项目路径到sys.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

import logging
from MySQLDatabaseTool import MySQLDatabaseTool


def test_hailin():
    mySQLDatabaseTool = MySQLDatabaseTool(host='192.168.125.23', port=3306, user='root', password='123456',
                                          database='test_db_hailin')
    results = mySQLDatabaseTool.show_databases()
    logging.info(results)
    mySQLDatabaseTool.connect()
    # mySQLDatabaseTool.create_database('test_db_hailin')
    mySQLDatabaseTool.use_database('test_db_hailin')
    mySQLDatabaseTool.create_table('test_table', [
        {
            'name': 'id',
            'type': 'INT',
            'primary_key': True,
            'auto_increment': True
        },
        {
            'name': 'name',
            'type': 'VARCHAR(255)',
            'not_null': True
        },
        {
            'name': 'age',
            'type': 'INT',
            'default': 0
        }
    ])
    mySQLDatabaseTool.cursor.execute("INSERT INTO test_table (name, age) VALUES (%s, %s)", ('hailin1', 182))
    mySQLDatabaseTool.connection.commit()

    mySQLDatabaseTool.close()
